<template>
  <div class="more-container">
    <div class="shortcutslist">
      <el-row>
        <h2>快捷操作</h2>
        <div class="setBox">
          <el-col :span="6" v-for="(p,index) in shortcutsList.choose" :key="index">
            <div class="colorBox">
              <div class="setitem" @click="cancelset(p)">
                <div class="backWhite" v-if="p.choose"></div>
                <div class="vab-remix-icon-box">
                  <vab-remix-icon :icon-class="p.quickIcon" class="vab-remix-icon" />
                </div>
                <div class="right-info">
                  <h3>{{p.title}}</h3>
                  <p>{{p.description}}</p>
                </div>
              </div>
            </div>
          </el-col>
        </div>
      </el-row>
      <div v-for="(value,key,index)  in shortcutsList.list" :key="key">
        <el-row>
          <h2>{{key}}</h2>
          <div class="setBox">
            <el-col :span="6" v-for="(p,index) in value" :key="index">
              <div class="colorBox">
                <div class="setitem" @click="set(p)">
                  <div class="backWhite" v-if="p.choose"></div>
                  <div class="vab-remix-icon-box">
                    <vab-remix-icon :icon-class="p.quickIcon" class="vab-remix-icon" />
                  </div>
                  <div class="right-info">
                    <h3>{{p.title}}</h3>
                    <p>{{p.description}}</p>
                  </div>
                </div>
              </div>
            </el-col>
          </div>
        </el-row>
      </div>


    </div>
  </div>
</template>


<script>
  //api
  import {
    quickoperationoption,
    setquickoperation
  } from '@/api/common'
  export default {
    data() {
      return {
        shortcutsList: [],
        //已选列表
        currentList: []
      }
    },
    methods: {
      async getquickoperationoption() {
        let data = await quickoperationoption()


        this.shortcutsList = data.data
         let arr=[]
        for (let p in this.shortcutsList.list) {
          this.shortcutsList.list[p].forEach(i => {
            if (i.choose) {
              arr.push(i.id)
            }
          })
        }
        this.currentList=arr
        console.log(this.currentList)
      },
      set(val) {

       if (this.currentList.indexOf(val.id) == -1) {
         if(this.currentList.length>=4){
           this.$message({
             message: '最多只能设置4个快捷操作',
             type: 'error'
           });
           return;
         }
         this.currentList.push(val.id)
       } else {
         if(this.currentList.length==1){
           this.$message({
             message: '请至少保留一个快捷操作',
              type: 'error'
           });
           return;
         }
         this.currentList.splice(this.currentList.indexOf(val.id), 1)
       }
        this.setstate()

      },
      cancelset(val) {
        if(this.currentList.length==1){
          this.$message({
            message: '请至少保留一个快捷操作',
             type: 'error'
          });
          return;
        }
        this.currentList.splice(this.currentList.indexOf(val.id), 1)
        this.setstate()
      },
      async setstate() {
        let params = {
          ruleId: this.currentList.join(',')
        }
        let data = await setquickoperation(params)
        if (data.code == '0000') {

          this.getquickoperationoption()
        }
      }
    },
    components: {},
    mounted() {
      this.getquickoperationoption()
    },
  }
</script>

<style scoped lang='scss'>
#remix-icon-setting-6{
  width: 32px;
}
  .shortcutslist {
    .svg-icon{
      height: auto !important;
    }
    .setBox {
      margin: 0;
      padding: 0;

      .colorBox {
        padding: 10px;
      }

      .vab-remix-icon-box {
        width: 32px;
        height: 32px;
        border-radius: 50%;
        display: flex;
        justify-content: center;
        overflow: hidden;
        align-items: center;
        .vab-remix-icon{
            font-size: 30px;
        }

      }

      .setitem {
        list-style: none;
        margin: 0;
        background: #f4f6ff;
        border-radius: 5px;
        display: flex;
        align-items: center;
        padding: 20px;
        box-sizing: border-box;
        cursor: pointer;
        position: relative;

        overflow: hidden;

        .backWhite {
          width: 100%;
          height: 100%;
          background-color: red;
          opacity: .5;
          position: absolute;
          left: 50%;
          top: -85%;
          transform: rotate(45deg);
          -ms-transform: rotate(45deg);
          /* IE 9 */
          -moz-transform: rotate(45deg);
          /* Firefox */
          -webkit-transform: rotate(45deg);
          /* Safari 和 Chrome */
          -o-transform: rotate(45deg);
        }

        .right-info {
          margin-left: 10px;

          h3 {
            margin: 0;
            padding: 0;
          }

          p {

            margin: 0;
            padding: 0;
            margin-top: 5px;
            font-size: 12px;
            color: #5e6e89;
          }
        }
      }
    }
  }
</style>
